#include "heroplane.h"
#include<file.h>
heroplane::heroplane() {
    m_plane.load(":/role.png");
    m_x=(GAME_WIDTH-m_plane.width())*0.5;
    m_y=GAME_HEIGHT-m_plane.height();
    m_Rect.setWidth(m_plane.width());
    m_Rect.setHeight(m_plane.height());
    m_Rect.moveTo(m_x,m_y);

}
void heroplane::shoot()
{
    m_recorder++;
    if(m_recorder<BULLET_INTERVAL){
        return;
    }
    m_recorder=0;
    for(int i=0;i<BULLET_NUM;i++){
        if(m_bullets[i].m_free){
            m_bullets[i].m_free=false;
            m_bullets[i].m_x=m_x+m_Rect.width()*0.5+10;
            m_bullets[i].m_y=m_y-25;
            break;
        }
    }
}

void heroplane::setPosition(int x, int y)
{
    m_x=x;
    m_y=y;
    m_Rect.moveTo(m_x,m_y);
}

void heroplane::moveLeft() {
    m_x -= 10;
    if (m_x < 0) m_x = 0;
    m_Rect.moveTo(m_x, m_y);
}
void heroplane::moveRight() {
    m_x += 10;
    if (m_x > GAME_WIDTH - m_Rect.width()) m_x = GAME_WIDTH - m_Rect.width();
    m_Rect.moveTo(m_x, m_y);
}
void heroplane::moveUp() {
    m_y -= 10;
    if (m_y < 0) m_y = 0;
    m_Rect.moveTo(m_x, m_y);
}
void heroplane::moveDown() {
    m_y += 10;
    if (m_y > GAME_HEIGHT - m_Rect.height()) m_y = GAME_HEIGHT - m_Rect.height();
    m_Rect.moveTo(m_x, m_y);
}
